$(function(){
//获取上一个页面的数据
function GetRequest() {
	var url = location.search; //获取url中"?"符后的字串 
	var theRequest = new Object();
	if (url.indexOf("?") != -1) {
		var str = url.substr(1);
		strs = str.split("&");
		for (var i = 0; i < strs.length; i++) {
			theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
		}
	}
	return theRequest;
}
var Request = new Object();
Request = GetRequest();



//alert(Request['id']);
//用来让下一个页面获取上一个页面的参数

var removeChildNodes = function($, own) {
			if ($ == null) {
				return;
			}
			while ($.hasChildNodes()) {
				$.removeChild($.firstChild);
			}
			if (own) {
				$.parentNode.removeChild($);
			}
};
	

 function getLocalTime(nS) {     
    return new Date(parseInt(nS) * 1000).toLocaleString().replace(/年|月/g,"-").replace(/日/g,"");      
}	
function formatSeconds(value) {
		var theTime = parseInt(value); // 秒
		var theTime1 = 0; // 分
		var theTime2 = 0; // 小时
		if (theTime > 60) {
			theTime1 = parseInt(theTime / 60);
			theTime = parseInt(theTime % 60);
			if (theTime1 > 60) {
				theTime2 = parseInt(theTime1 / 60);
				theTime1 = parseInt(theTime1 % 60);
			}
		}
			var result = "" + parseInt(theTime) + "秒";
		if (theTime1 > 0) {
			result = "" + parseInt(theTime1) + "分" + result;
		}
		if (theTime2 > 0) {
			result = "" + parseInt(theTime2) + "小时" + result;
		}
		return result;
}

//删除子节点
var removeChildNodes = function($, own) {
		if ($ == null) {
			return;
		}
		while ($.hasChildNodes()) {
			$.removeChild($.firstChild);
		}
		if (own) {
			$.parentNode.removeChild($);
		}
};


		$.ajax({ 
			type:"GET",
		    dataType:"json",
		    //url:'http://192.168.0.12:8080/elink_video/course/getCourseContent/1',
		    url:"star.json",
		    success: function(result) {
			  	if(result.code==1000){
			  		var items = result.data.course;
	  		  		$('<div/>',{	      		  			
	  		  			html:
	  		  			'<div class="nav-box">'+
							'<div class="course-nav-hd clearfix">'+						
								'<span class="blod">'+
									'<a href="javascript:;">全部课程'+
									'</a>'+
								'</span>'+
								'>'+
								'<span class="step">'+
									'<a href="javascript:;">'+items.courseId+
									'</a>'+
								'</span>'+
								'>'+
								'<span class="step">'+
									'<a href="javascript:;">'+items.childTypeId+
									'</a>'+
								'</span>'+
								'>'+
								'<span class="step">'+
									'<a href="javascript:;">'+items.courseName+
									'</a>'+
								'</span>'+									
								'<div class="module-warp fr">'+
									'<a href="course.html" class="module">视频专区'+
									'</a>'+
									'<a href="identification.html" class="module">视频上传'+
									'</a>'+
								'</div>'+
								'<div class="search-warp clearfix">'+
					            	'<div class="search-area min" data-search="top-banner">'+
					               	 	'<input class="search-input"  placeholder="请输入想搜索的内容..." type="text" autocomplete="off">'+
					               	 	  '<ul class="search-result" style="display: none;">'+
						               	 		'<li>高等数学'+
						               	 		'</li>'+
						               	 		'<li>大学物理'+
						               	 		'</li>'+
						               	 		'<li>高等数学'+
						               	 		'</li>'+
						               	 		'<li>大学物理'+
						               	 		'</li>'+
						               	 		'<li class="case">清空搜索选项'+						               	 		
						               	 		'</li>'+
					               	 		'</ul>'+
					            	'</div>'+
					           		'<div class="showhide-search" data-show="no">'+
					           			'<i class="icon-search">'+
					           			'</i>'+
					           		'</div>'+
					        	'</div>'+
							'</div>'+
						'</div>'+
						'<div class="imgtext-course clearfix">'+
							'<div class="imgtext fl">'+
								'<img src="http://192.168.0.12:8080/elink_video/'+items.coverUrl+'"/>'+
							'</div>'+
							'<div class="text-right fl">'+
								'<h2>'+items.courseName+
								'</h2>'+
								'<div class="score clearfix">'+
									'<span>综合评分 :'+
										'<em class="totalScore">'+items.totalScore+
										'</em>'+
									'</span>'+
									'<ul class="star clearfix" id="star">'+
										'<li>'+
											'<a href="javascript:void(0)" title="1" class="one-star">'+1+
											'</a>'+
										'</li>'+
										'<li>'+
											'<a href="javascript:void(0)" title="2" class="two-stars">'+2+
											'</a>'+
										'</li>'+
										'<li>'+
											'<a href="javascript:void(0)" title="3" class="three-stars">'+3+
											'</a>'+
										'</li>'+
										'<li>'+
											'<a href="javascript:void(0)" title="4" class="four-stars">'+4+
											'</a>'+
										'</li>'+
										'<li>'+
											'<a href="javascript:void(0)" title="5" class="five-stars">'+5+
											'</a>'+
										'</li>'+
										'<div class="current-rating" id="showb">'+
										'</div>'+
									'</ul>'+									
								'</div>'+
								'<div class="text-msg">'+
									'<span class="frequency">播放'+
										'<em>'+items.playTimes+
										'</em>万次'+
									'</span>'+
									'<span class="collect">收藏'+
										'<em>'+items.collectionTimes+
										'</em>'+
									'</span>'+
									'<span class="time">'+getLocalTime(items.createTime)+
									'</span>'+
								'</div>'+
								'<span class="prices">'+
									'￥'+
									'<em>'+items.price+
									'</em>'+
								'</span>'+
								'<div class="oper-bar">'+
//									'<div class="oper-bar">'+
//										'<span class="sign oper-sign">立即报名'+
//										'</span>'+
//									'</div>'+
								'</div>'+					
							'</div>'+
						'</div>'+
						'<span class="report">'+
							'<a href="javascript:;">举报'+
							'</a>'+
						'</span>'
	  		  		}).appendTo('.'+'course-content');
			  	}
			  		if($("#totalScore").html()>8 && $("#totalScore").html()<10){
						$("#showb").css("background-position","0px 0px")
						$("#showb").css("left","0px");
					}else if($("#totalScore").html()>6 && $("#totalScore").html()<8){
						$("#showb").css("background-position","0px 0px");
						$("#showb").css("left","-16px");
					}else if(Number($("#totalScore").html())>4 && Number($("#totalScore").html())<6){
						$("#showb").css("background-position","0px 0px");
						$("#showb").css("left","-48px");
					}else if(Number()>1 && $("#totalScore").html()<4){
						$("#showb").css("background-position","0px 0px");
						$("#showb").css("left","-64px");
					}else{
						$("#showb").css("background-position","0px 0px");
						$("#showb").css("left","-48px");
					}
		    },
		     error:function(jqXHR){     
		       alert("发生错误：" + jqXHR.status)  
		    } 
	});
	
	//简介列表
	$(".abstract").on('click',function(){			
			$.ajax({ 
				type:"GET",
			    dataType:"json",
			    //url:'http://192.168.0.12:8080/elink_video/course/getCourseContent/1',
			    url:"star.json",
			    success: function(result) {
					if(result.code==1000){
			  		var items = result.data.course;			  		
		  		  		$('<div/>',{	      		  			
		  		  			html:
							'<div class="price-left-bd">'+
								'<p class="price_1">'+items.describes+
								'</p>'+
							'</div>'		  		  			
		  		  		}).appendTo('.'+'price-left-content');
					}
			    },
			     error:function(jqXHR){     
			       alert("发生错误：" + jqXHR.status)  
			    } 
		});
	})
	
	
			$.ajax({ 
				type:"GET",
			    dataType:"json",
			    //url:'http://192.168.0.12:8080/elink_video/course/getCourseContent/1',
			    url:"star.json",
			    success: function(result) {					
					var items=result.data.course;				
					$(".comment-box").before(
						'<div class="comment-title">'+
							'<div class="comment-statistics">'+
								'<span>综合评分 :'+
									'<em class="totalScore">'+items.totalScore+
									'</em>'+
								'</span>'+
									'<ul class="star clearfix" id="star">'+
										'<li>'+
											'<a href="javascript:void(0)" title="1" class="one-star">'+1+
											'</a>'+
										'</li>'+
										'<li>'+
											'<a href="javascript:void(0)" title="2" class="two-stars">'+2+
											'</a>'+
										'</li>'+
										'<li>'+
											'<a href="javascript:void(0)" title="3" class="three-stars">'+3+
											'</a>'+
										'</li>'+
										'<li>'+
											'<a href="javascript:void(0)" title="4" class="four-stars">'+4+
											'</a>'+
										'</li>'+
										'<li>'+
											'<a href="javascript:void(0)" title="5" class="five-stars">'+5+
											'</a>'+
										'</li>'+
										'<div class="current-rating" id="showb">'+
										'</div>'+
									'</ul>'+
							'</div>'+
							'<div class="filter-comment-rank">'+
								'<span>内容使用 :'+
									'<em>'+items.evaluateA+
									'</em>'+
								'</span>'+
								'<span>简单易懂 :'+
									'<em>'+items.evaluateB+
									'</em>'+
								'</span>'+
								'<span>逻辑清晰 :'+
									'<em>'+items.evaluateC+
									'</em>'+
								'</span>'+
								'<span class="comment-num">评论('+
								'<em>'+items.evaluateAmount+
								'</em>'+
								')'+
								'</span>'+
							'</div>'+
						'</div>'
					);
										
					if($(".comment-tips-msg .totalScores").html()>8 && $(".comment-tips-msg.totalScores").html()<10){
						$(".comment-statistics #showb").css("background-position","0px 0px")
						$(".comment-statistics #showb").css("left","0px");
					}else if($(".totalScore").html()>6 && $(".totalScore").html()<8){
						$(".comment-statistics #showb").css("background-position","0px 0px");
						$(".comment-statistics #showb").css("left","-16px");
					}else if($(".totalScore").html()>4 && $(".totalScore").html()<6){
						$(".comment-statistics #showb").css("background-position","0px 0px");
						$(".comment-statistics #showb").css("left","-48px");
					}else if($(".totalScore").html()>1 && $(".totalScore").html()<4){
						$(".comment-statistics #showb").css("background-position","0px 0px");
						$(".comment-statistics #showb").css("left","-64px");
					}else{
						$(".comment-statistics #showb").css("background-position","0px 0px");
						$(".comment-statistics #showb").css("left","-48px");
					}
					
			    },
			     error:function(jqXHR){     
			       alert("发生错误：" + jqXHR.status)  
			    } 
		});
		
			$.ajax({ 
				type:"GET",
			    dataType:"json",
			    //url:'http://192.168.0.12:8080/elink_video/evaluate/getCourseEvaluate/1',
			    url:"satr1.json",
			    success: function(result) {
			    	//console.log(.score);
					var items=result.data;
					for(var i=0;i<items.length;i++){
						

						$(".comment-msg").before(
							'<div class="comment-tips clearfix">'+
							'<div class="comment-user fl">'+
								'<a class="comment-tips-user">'+
								'<img src="http://192.168.0.12:8080/elink_video/'+items[i].logo+'"/>'+
								'</a>'+
								'<span>'+items[i].nickname+
								'</span>'+
							'</div>'+
							'<div class="comment-tips-msg fl">'+
								'<em class="totalScore">'+items[i].score+
								'</em>'+
								'<ul class="star clearfix" id="star">'+
										'<li>'+
											'<a href="javascript:void(0)" title="1" class="one-star">'+1+
											'</a>'+
										'</li>'+
										'<li>'+
											'<a href="javascript:void(0)" title="2" class="two-stars">'+2+
											'</a>'+
										'</li>'+
										'<li>'+
											'<a href="javascript:void(0)" title="3" class="three-stars">'+3+
											'</a>'+
										'</li>'+
										'<li>'+
											'<a href="javascript:void(0)" title="4" class="four-stars">'+4+
											'</a>'+
										'</li>'+
										'<li>'+
											'<a href="javascript:void(0)" title="5" class="five-stars">'+5+
											'</a>'+
										'</li>'+
										'<div class="current-rating" id="showb">'+
										'</div>'+
									'</ul>'+
								'<div class="comment-tips-title">'+items[i].evaluateContent+
								'</div>'+
								'<ul class="comment-part">'+
									'<li class="comment-list">'+
										'<span class="time">'+getLocalTime(items[i].createTime)+									
										'</span>'+

									'</li>'+
								'</ul>'+
							'</div>'+

						'</div>'
						);						
					}

					
				},
			     error:function(jqXHR){     
			       alert("发生错误：" + jqXHR.status)  
			    } 
		});

		
		$.ajax({ 
				type:"GET",
			    dataType:"json",
			    url:'http://192.168.0.12:8080/elink_user/user/getUserInfo/2b54e719b2ad46a193a2851849ba3451',
			    success: function(result) {			    	
			    	//console.log(.score);
					var items=result.data;					
						$(".course-price").append(
						'<div class="price-right fl">'+
						'<h4 class="">个人介绍</h4>'+
						'<div class="user-info clearfix">'+
								'<a href="javascript:;">'+
								'<img src="http://192.168.0.12:8080/elink_video/'+items.logo+'"/>'+
								'</a>'+
								'<div class="user-info-right fl">'+
									'<div class="user-msg">'+
										'<a href="" class="user">'+items.nickname+
										'</a>'+
										'<a class="follow">+ 关注</a>'+
									'</div>'+
									'<span class="video">视频 <em>9</em></span>'+
									'<span class="fans">粉丝 <em>199</em></span>'+
								'</div>'+
						'</div>'+
						'<div class="user-info-tip">'+
						'<p>'+items.describes+
						'</p>'+
						'</div>'+
						'</div>'
						);
					
			    }
				,
			     error:function(jqXHR){     
			       alert("发生错误：" + jqXHR.status)  
			    }
		});

	
	//免费视频的选项卡切换
	$(".price-left-tab ul li").click(function(){
		$(this).addClass("active").siblings().removeClass("active");
		var _index=$(".price-left-tab ul li").index(this);
		$(".price-left-bd").eq(_index).show().siblings().hide();
	})
	//搜索显示与隐藏
	$(function(e) {
	   var $area = $('.search-area'),
	        $showhide = $('.showhide-search'),
	        $input = $('.search-input');      
	    $('.course-nav-hd').on('click', '.showhide-search', function (event){
	        var isShow = $(this).attr('data-show');
	        if( isShow == 'no'){
	            show()
	            $input.focus();
	            $input.keyup(function(){
	            	$(".search-result").css("display","block");
	            });
	            $(".search-input").css("border","1px solid #bcbcbc");
	        }else{
	        	if($input.val()==""){
	        		hide()
	        	}
	        }                    
	        return false;
	    })        
	    $('.course-nav-hd').on('click', '.search-area', function (event){
	        return false;
	    })         
	    $(document).on('click', function (){
	        if( $input.val() != ''){
	            hide()
	        }else{
	        	hide()
	        }
	    })       
	    var show = function (){
	        $showhide.attr('data-show', 'yes')
	        $area.show(1, function (){ $area.removeClass('min') })
	    }     
	    var hide = function (){
	        $showhide.attr('data-show', 'no')
	        $area.fadeOut('slow', function (){
	            $area.addClass('min')
	        })
	    }
	})
})